import Banner from "../Banner";
import { 头盔, 手枪, 防弹衣, 突击步枪, 冲锋枪, 射手步枪, 栓动步枪, 轻机枪, 霰弹枪, 卡宾枪, 投掷物, 子弹, 药品, 食物, ItemData, } from "../Datas/Data";
import { Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { BundleManager, Bundles } from "../Framework/Managers/BundleManager";
import { DataManager } from "../Framework/Managers/DataManager";
import { UIManager } from "../Framework/Managers/UIManager";
import NodeUtil from "../Framework/Utils/NodeUtil";
import { ResourceUtil } from "../Framework/Utils/ResourceUtil";
import { ZTool } from "../Framework/Utils/ZTool";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SkinItem extends cc.Component {

    Icon: cc.Sprite = null;
    Name: cc.Label = null;

    data: ItemData;

    protected onLoad(): void {
        this.Icon = NodeUtil.GetComponent("Icon", this.node, cc.Sprite);
        this.Name = NodeUtil.GetComponent("Name", this.node, cc.Label);
    }

    Init(data) {
        this.Name.string = `${data.Name}`;
        this.Icon.node.setScale(1);
        BundleManager.LoadSpriteFrame(Bundles.Item, `${data.Type}_${data.Name}`).then((sf: cc.SpriteFrame) => {
            this.Icon.spriteFrame = sf;
        });
    }

    头盔(data: 头盔) {
        this.data = data;
        this.Init(data);
        this.Icon.node.setScale(0.7);
    }

    防弹衣(data: 防弹衣) {
        this.data = data;
        this.Init(data);
        this.Icon.node.setScale(0.8);
    }

    手枪(data: 手枪) {
        this.data = data;
        this.Init(data);
    }

    突击步枪(data: 突击步枪) {
        this.data = data;
        this.Init(data);
    }

    冲锋枪(data: 冲锋枪) {
        this.data = data;
        this.Init(data);
    }

    射手步枪(data: 射手步枪) {
        this.data = data;
        this.Init(data);
    }

    栓动步枪(data: 栓动步枪) {
        this.data = data;
        this.Init(data);
    }

    轻机枪(data: 轻机枪) {
        this.data = data;
        this.Init(data);
    }

    霰弹枪(data: 霰弹枪) {
        this.data = data;
        this.Init(data);
    }

    卡宾枪(data: 卡宾枪) {
        this.data = data;
        this.Init(data);
    }

    投掷物(data: 投掷物) {
        this.data = data;
        this.Init(data);
    }

    子弹(data: 子弹) {
        this.data = data;
        this.Init(data);
        this.Icon.node.setScale(0.8);
    }

    药品(data: 药品) {
        this.data = data;
        this.Init(data);
        this.Icon.node.setScale(ItemData.GetScale(data.Type));
    }

    食物(data: 食物) {
        this.data = data;
        this.Init(data);
    }

    OnButtonClick() {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);
        Banner.Instance.ShowVideoAd(() => {
            DataManager.AddPlayerItem(ZTool.DeepCopy(this.data));
            UIManager.Instance.ShowPanel(Constant.Panel.RewardPanel, [this.data])
        });
    }

}
